package com.example.perpetualcalendar.ui.fragment.joke;

import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.example.perpetualcalendar.R;
import com.example.perpetualcalendar.base.BaseFragment;
import com.example.perpetualcalendar.databinding.FragmentNotificationsBinding;


/**
 * @author langhua
 */
public class JokeFragment extends BaseFragment<JokeViewModel, FragmentNotificationsBinding> {


    @Override
    protected void initView() {
        mViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                ScaleAnimation scaleAnimation = (ScaleAnimation) AnimationUtils.loadAnimation(getContext(), R.anim.scale);
                viewBinding.cardView.startAnimation(scaleAnimation);
                viewBinding.textJoke.setText(s);
            }
        });
        viewBinding.button.setOnClickListener((v -> mViewModel.joke()));
    }

    @NonNull
    @Override
    protected Class<JokeViewModel> setViewModel() {
        return JokeViewModel.class;
    }

    @NonNull
    @Override
    protected int setLayout() {
        return R.layout.fragment_notifications;
    }

}